﻿using Booking.Salary;
using Microsoft.EntityFrameworkCore;

namespace Booking
{
    public class BookingContext : DbContext
    {


        protected override void OnConfiguring(DbContextOptionsBuilder options)
            => options.UseSqlite("Data Source=Salary.db");
        public DbSet<SalaryItem> SalaryItems { set; get; }
        public DbSet<Salary.Salary> Salarys { set; get; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<SalaryItem>().Property(si => si.Name).IsRequired();//名字是必须的
            modelBuilder.Entity<SalaryItem>().Property(si => si.Name).HasMaxLength(20);//名字是必须的
            modelBuilder.Entity<SalaryItem>().Property(si => si.SalaryType).IsRequired();//名字是必须的
            modelBuilder.Entity<Salary.Salary>().Property(s => s.Item).IsRequired();
            modelBuilder.Entity<Salary.Salary>().Property(s => s.Inserted).ValueGeneratedOnAdd();
           /modelBuilder.Entity<Salary.Salary>().HasOne(s => s.Item).WithMany().HasForeignKey(s => s.Item.Id);


        }

    }
}

